//-
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

include /app/helpers/jade/mixins
include /app/configuration/mixins

-var form = 'misc'
-var model = 'backupItem'
-var pathModes = `${model}.pathModes`

panel-collapsible(ng-form=form on-open=`ui.loadPanel('${form}')`)
    panel-title Miscellaneous
    panel-description Various miscellaneous IGFS settings.
    panel-content.pca-form-row(ng-if=`ui.isPanelLoaded('${form}')`)
        .pca-form-column-6.pc-form-grid-row
            .pc-form-grid-col-60
                +form-field__number({
                    label: 'Block size:',
                    model: `${model}.blockSize`,
                    name: '"blockSize"',
                    placeholder: '65536',
                    min: '0',
                    tip: 'File data block size in bytes'
                })

            //- Since ignite 2.0
            .pc-form-grid-col-60(ng-if='$ctrl.available("2.0.0")')
                +form-field__number({
                    label: 'Buffer size:',
                    model: `${model}.streamBufferSize`,
                    name: '"streamBufferSize"',
                    placeholder: '65536',
                    min: '0',
                    tip: 'Read/write buffer size for IGFS stream operations in bytes'
                })

            //- Removed in ignite 2.0
            .pc-form-grid-col-60(ng-if-start='$ctrl.available(["1.0.0", "2.0.0"])')
                +form-field__number({
                    label: 'Stream buffer size:',
                    model: `${model}.streamBufferSize`,
                    name: '"streamBufferSize"',
                    placeholder: '65536',
                    min: '0',
                    tip: 'Read/write buffer size for IGFS stream operations in bytes'
                })
            .pc-form-grid-col-60(ng-if-end)
                +form-field__number({
                    label: 'Maximum space size:',
                    model: `${model}.maxSpaceSize`,
                    name: '"maxSpaceSize"',
                    placeholder: '0',
                    min: '0',
                    tip: 'Maximum space available for data cache to store file system entries'
                })

            .pc-form-grid-col-30
                +form-field__number({
                    label: 'Maximum task range length:',
                    model: `${model}.maximumTaskRangeLength`,
                    name: '"maximumTaskRangeLength"',
                    placeholder: '0',
                    min: '0',
                    tip: 'Maximum default range size of a file being split during IGFS task execution'
                })
            .pc-form-grid-col-30
                +form-field__number({
                    label: 'Management port:',
                    model: `${model}.managementPort`,
                    name: '"managementPort"',
                    placeholder: '11400',
                    min: '0',
                    max: '65535',
                    tip: 'Port number for management endpoint'
                })
            .pc-form-grid-col-30
                +form-field__number({
                    label: 'Per node batch size:',
                    model: `${model}.perNodeBatchSize`,
                    name: '"perNodeBatchSize"',
                    placeholder: '100',
                    min: '0',
                    tip: 'Number of file blocks collected on local node before sending batch to remote node'
                })
            .pc-form-grid-col-30
                +form-field__number({
                    label: 'Per node parallel batch count:',
                    model: `${model}.perNodeParallelBatchCount`,
                    name: '"perNodeParallelBatchCount"',
                    placeholder: '8',
                    min: '0',
                    tip: 'Number of file block batches that can be concurrently sent to remote node'
                })
            .pc-form-grid-col-60
                +form-field__number({
                    label: 'Prefetch blocks:',
                    model: `${model}.prefetchBlocks`,
                    name: '"prefetchBlocks"',
                    placeholder: '8',
                    min: '0',
                    tip: 'Number of pre-fetched blocks if specific file chunk is requested'
                })
            .pc-form-grid-col-60
                +form-field__number({
                    label: 'Sequential reads before prefetch:',
                    model: `${model}.sequentialReadsBeforePrefetch`,
                    name: '"sequentialReadsBeforePrefetch"',
                    placeholder: '8',
                    min: '0',
                    tip: 'Amount of sequential block reads before prefetch is triggered'
                })

            //- Removed in ignite 2.0
            .pc-form-grid-col-60(ng-if='$ctrl.available(["1.0.0", "2.0.0"])')
                +form-field__number({
                    label: 'Trash purge timeout:',
                    model: `${model}.trashPurgeTimeout`,
                    name: '"trashPurgeTimeout"',
                    placeholder: '1000',
                    min: '0',
                    tip: 'Maximum timeout awaiting for trash purging in case data cache oversize is detected'
                })

            .pc-form-grid-col-60
                +form-field__checkbox({
                    label: 'Colocate metadata',
                    model: `${model}.colocateMetadata`,
                    name: '"colocateMetadata"',
                    tip: 'Whether to co-locate metadata on a single node'
                })
            .pc-form-grid-col-60
                +form-field__checkbox({
                    label: 'Relaxed consistency',
                    model: `${model}.relaxedConsistency`,
                    name: '"relaxedConsistency"',
                    tip: 'If value of this flag is <b>true</b>, IGFS will skip expensive consistency checks<br/>\
                         It is recommended to set this flag to <b>false</b> if your application has conflicting\
                         operations, or you do not know how exactly users will use your system'
                })

            //- Since ignite 2.0
            .pc-form-grid-col-60(ng-if='$ctrl.available("2.0.0")')
                +form-field__checkbox({
                    label: 'Update file length on flush',
                    model: model + '.updateFileLengthOnFlush',
                    name: '"updateFileLengthOnFlush"',
                    tip: 'Update file length on flush flag'
                })

            .pc-form-grid-col-60
                mixin igfs-misc-path-modes
                    .ignite-form-field
                        +form-field__label({ label: 'Path modes:', name: '"pathModes"' })
                            +form-field__tooltip({ title: `Map of path prefixes to IGFS modes used for them` })

                        -let items = pathModes

                        list-editable(ng-model=items)
                            list-editable-item-view
                                | {{ $item.path + " [" + $item.mode + "]"}}

                            list-editable-item-edit
                                - form = '$parent.form'

                                .pc-form-grid-row
                                    .pc-form-grid-col-30
                                        +form-field__text({
                                            label: 'Path:',
                                            model: '$item.path',
                                            name: '"path"',
                                            required: true,
                                            placeholder: 'Enter path'
                                        })(ignite-auto-focus)
                                    .pc-form-grid-col-30
                                        +form-field__dropdown({
                                            label: 'Mode:',
                                            model: `$item.mode`,
                                            name: '"mode"',
                                            required: true,
                                            placeholder: 'Choose igfs mode',
                                            options: '{{::$ctrl.IGFSs.defaultMode.values}}'
                                        })(
                                            ng-model-options='{allowInvalid: true}'
                                        )

                            list-editable-no-items
                                list-editable-add-item-button(
                                    add-item=`$editLast((${items} = ${items} || []).push({}))`
                                    label-single='path mode'
                                    label-multiple='path modes'
                                )

                +igfs-misc-path-modes

        .pca-form-column-6
            +preview-xml-java(model, 'igfsMisc')
